#pragma once

#include "muduo/net/Buffer.h"

#include "interface/msg/car_information.hpp"
#include "interface/msg/gnss.hpp"
#include "interface/msg/objects.hpp"
#include "interface/msg/point_clouds.hpp"
#include <rclcpp/rclcpp.hpp>

#include <map>
#include <memory>

namespace sensor::radar {

class CanTransreceiver;

class CanAdapter : public rclcpp::Node {
public:
    CanAdapter(std::unordered_map<std::string, std::shared_ptr<CanTransreceiver>> devs, const std::string& adapter_name);
    void canSend(std::string dev,int frameid, muduo::net::Buffer& buf);

private:
    virtual void onReceiveCanMessage(const std::string& dev, int fid, muduo::net::Buffer& buffer) = 0;
    virtual void onReceiveGnssMessage(const interface::msg::Gnss::SharedPtr msg) = 0;
    virtual void onReceiveInformationMessage(const interface::msg::CarInformation msg) = 0;

protected:
    std::unordered_map<std::string, std::shared_ptr<CanTransreceiver>> can_devs_;
    rclcpp::Logger logger_;

    std::unordered_map<std::string, rclcpp::Publisher<interface::msg::Objects>::SharedPtr> radar_obj_pubs_;
    std::unordered_map<std::string, rclcpp::Publisher<interface::msg::PointClouds>::SharedPtr> radar_pc_pubs_;
    std::unordered_map<std::string, rclcpp::Subscription<interface::msg::Gnss>::SharedPtr> gnss_subs_;
    rclcpp::Publisher<interface::msg::CarInformation>::SharedPtr body_information_pubs_;
    rclcpp::Subscription<interface::msg::CarInformation>::SharedPtr body_information_subs_;
};

}